package com.fowo.api.mp.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Data
public class WxSubscribeMessage {

    public WxSubscribeMessage(String templateId, String toUser) {
        this.templateId = templateId;
        this.toUser = toUser;
    }

    public WxSubscribeMessage addData(String name, String value) {
        final TemplateData templateData = new TemplateData();
        templateData.setValue(value);
        this.data.put(name, templateData);
        return this;
    }

    /**
     * 接收者（用户）的 openid
     */
    @JsonProperty("touser")
    private String toUser;

    /**
     * 所需下发的订阅模板id
     */
    private String templateId;

    /**
     * 点击模板卡片后的跳转页面，仅限本小程序内的页面。支持带参数,（示例index?foo=bar）。该字段不填则模板无跳转
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String page;

    /**
     * 跳转小程序类型：developer为开发版；trial为体验版；formal为正式版；默认为正式版
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String miniprogramState;

    /**
     * 进入小程序查看”的语言类型，支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文)，默认为zh_CN
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String lang;

    /**
     * 模板内容，格式形如 { "key1": { "value": any }, "key2": { "value": any } }
     */
    private Map<String,TemplateData> data = new ConcurrentHashMap<>();

    @Data
    public static class TemplateData {
        private String value;
    }
}
